<?php
namespace app\upload_file\controller;
use \think\Controller;
use\think\db;
class UploadFile extends Base {

    //上传文件
    public function upload_photo(){
        $data = $this->data;
        $is_pms = input('param.is_pms',0);
        if(!empty($_FILES['voice']['tmp_name'])){
            $folder = 'listen/0/';
            $config = array(
                'size' =>   2097152,//2M
                'ext'  =>   'mp3,acc,wav,png,jpg,jpeg,gif,bmp,xls,xlsx,doc,docx,ppt,pptx,pdf,txt,pem,p12,mobileprovision,',
            );
            $fileInfo = $this->uploadfile_qiniu($config,$folder,$is_pms);
            if($fileInfo['status']==1){
                if($is_pms == 1){
                    $web_set = \app\common\model\Base::get_domain_set();
                    $fileInfo['data']['url'] = $web_set['qn_domain'].$fileInfo['data']['url'];
                    unset($web_set);
                }
				//return $fileInfo['data'];
               return api_return(22222,(array)$fileInfo['data']);
            }else{
                return api_return(-10006);
            }
        }else{
            return api_return(-10034);
        }
    }

    /*****
     * 服务器上传单个文件
     */
    public function  one_upload(){
//        header("Content-type:text/html;charset=utf-8");
        $data = $this->data;
        if(!empty($_FILES['voice']['tmp_name'])){
            $folder = 'uploadfile/voice/';
            $config = array(
                'size' =>   2097152,//2M
                'ext'  =>   'aac,wav,mp3,png,jpg,jpeg,gif,bmp,xls,xlsx,doc,docx,ppt,pptx,pdf,txt,pem,p12,mobileprovision',
            );
            $fileInfo = one_upload($folder,$config);
            if($fileInfo['status']==1){
                return api_return(22222,$fileInfo);
            }else{
                return api_return(-10006);
            }
        }else{
            return api_return(-10034);
        }
    }

    public function  test_up(){
        print_r($this->fetch());
    }
    public function tests()
    {
        $web_set = \app\common\model\Base::get_domain_set();
        print_r($web_set);die;
        header("Content-Type: text/plain");
        set_time_limit(0);

        $infoString = time() . "\n";
        while (isset($infoString)) {
            echo $infoString;
            flush();
            ob_flush();
            sleep(5);
        }
    }
}
